;-*2013*-*2013*-*2013*-*2013*-*2013*-*2013*-*2013*-*2013*-*2013*-
;
;HHS-SCIENCE-OLYMPIAD-2013-ROBOT-ARM-CONTROL-AHK-MAESTRO-CONTROL
;Version		: 1.0.0.2
;Authors		: ---
;Release Notes	: 1 - Clockwise - right - up // -1 - Counter-Clockwise - left - down

;Possition Variables: Storing the current possitions of the servos
varBaseTarg = 4500
varSholTarg = 4500
varElboTarg = 4500
varWrisTarg = 4500
varGripTarg = 4500

;Pin Variables: Which Slot are the parts in anyways
baseServo = 11
sholServo = 12
elboServo = 10
wrisServo = 9
gripServo = 8

;Lmit Variables: Define the minimum and maximum ranges of the servos
minBasePos = 700
minSholPos = 800
minElboPos = 600
minWrisPos = 600
minGripPos = 1100

maxBasePos = 9200
maxSholPos = 6800
maxElboPos = 9600
maxWrisPos = 9600
maxGripPos = 9600

;State Variables: Store the current 'state' of the robot
autoMode = 0
;hasInitialized = 0

;MAIN SEGMENT: PLACE HOTKEY CALLS, ROUTINES, ETC. HERE

!w::
while GetKeyState("Alt","P")
{
	while GetKeyState("W","P")
	{
		MoveBase(1) ; Move right
	}
}
return

!s::
while GetKeyState("Alt","P")
{
	while GetKeyState("S","P")
	{
		MoveBase(-1) ; Move left
	}
}
return

!a::
while GetKeyState("Alt","P")
{
	while GetKeyState("A","P")
	{
		MoveBase(1) 
	}
}
return

!d::
while GetKeyState("Alt","P")
{
	while GetKeyState("D","P")
	{
		MoveBase(1)
	}
}
return

!u::
while GetKeyState("Alt","P")
{
	while GetKeyState("U","P")
	{
		MoveBase(1)
	}
}
return

!j::
while GetKeyState("Alt","P")
{
	while GetKeyState("J","P")
	{
		MoveBase(1)
	}
}
return

!h::
while GetKeyState("Alt","P")
{
	while GetKeyState("H","P")
	{
		MoveBase(1)
	}
}
return

!k::
while GetKeyState("Alt","P")
{
	while GetKeyState("K","P")
	{
		MoveBase(1)
	}
}
return

!r::
while GetKeyState("Alt","P")
{
	while GetKeyState("R","P")
	{
		MoveBase(1)
	}
}
return

!f::
while GetKeyState("Alt","P")
{
	while GetKeyState("F","P")
	{
		MoveBase(1)
	}
}
return


;FUCTION SEGMENT: PLACE ANY FUCTIONS HERE
MoveBase(dir)
{
	if (dir > 0) ;If going forward
	{
		sum := dir + 100 ; add 100 millipulses to target
		if(sum < maxBasePos) ; if that doesn't break the max
		{
			Run usccmd --servo %servoBase%,%sum%,,Hide ; move there
			varBaseTarg := %sum% ; and save the new target
		}
	}
	else if (dir < 0)
	{
		difference := dir - 100
		if(difference > minBasePos) ; if that doesn't break the min
		{
			Run usccmd --servo %servoBase%,%difference%,,Hide ; move there
			varBaseTarg := %difference% ; and save the new target
		}
	}	
}

MoveShol(dir)
{
	if (dir > 0) ;If going forward
	{
		sum := dir + 100 ; add 100 millipulses to target
		if(sum < maxBasePos) ; if that doesn't break the max
		{
			Run usccmd --servo %servoShol%,%sum%,,Hide ; move there
			varSholTarg := %sum% ; and save the new target
		}
	}
	else if (dir < 0)
	{
		difference := dir - 100
		if(difference > minBasePos) ; if that doesn't break the min
		{
			Run usccmd --servo %servoShol%,%difference%,,Hide ; move there
			varSholTarg := %difference% ; and save the new target
		}
	}	
}

MoveElbo(dir)
{
	if (dir > 0) ;If going forward
	{
		sum := dir + 100 ; add 100 millipulses to target
		if(sum < maxBasePos) ; if that doesn't break the max
		{
			Run usccmd --servo %servoElbo%,%sum%,,Hide ; move there
			varElboTarg := %sum% ; and save the new target
		}
	}
	else if (dir < 0)
	{
		difference := dir - 100
		if(difference > minBasePos) ; if that doesn't break the min
		{
			Run usccmd --servo %servoElbo%,%difference%,,Hide ; move there
			varElboTarg := %difference% ; and save the new target
		}
	}	
}

MoveWris(dir)
{
	if (dir > 0) ;If going forward
	{
		sum := dir + 100 ; add 100 millipulses to target
		if(sum < maxBasePos) ; if that doesn't break the max
		{
			Run usccmd --servo %servoWris%,%sum%,,Hide ; move there
			varWrisTarg := %sum% ; and save the new target
		}
	}
	else if (dir < 0)
	{
		difference := dir - 100
		if(difference > minBasePos) ; if that doesn't break the min
		{
			Run usccmd --servo %servoWris%,%difference%,,Hide ; move there
			varWrisTarg := %difference% ; and save the new target
		}
	}	
}

MoveGrip(dir)
{
	if (dir > 0) ;If going forward
	{
		if(sum < maxBasePos) ; if that doesn't break the max
		{
			Run usccmd --servo %servoGrip%,%sum%,,Hide ; move there
			varGripTarg := %sum% ; and save the new target
		}
	}
	else if (dir < 0)
	{
		difference := dir - 100
		if(difference > minBasePos) ; if that doesn't break the min
		{
			Run usccmd --servo %servoGrip%,%difference%,,Hide ; move there
			varGripTarg := %difference% ; and save the new target
		}
	}	
}